package com.yzhl.batch_sync.interceptor;


import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.plugin.*;
import org.springframework.stereotype.Component;

import java.sql.Statement;
import java.util.Properties;

/**
 * @author wangzu
 * @date 2018/10/11
 */
@Intercepts({
        @Signature(type = ResultSetHandler.class, method = "handleResultSets", args = Statement.class)
})
//@Component
public class MybatisInterceptor implements Interceptor {


    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        System.out.println("intersept target: " + invocation.getTarget());
        System.out.println("intersept target getMethod: " + invocation.getMethod());
        System.out.println("intersept target getArgs: " + invocation.getArgs());
        Object object = invocation.proceed();
        return object;
    }

    @Override
    public Object plugin(Object target) {
        System.out.println("plugin target: " + target);
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {
        System.out.println("initial config properties" + properties);
    }
}
